package com.study.talk.module.entity;

import com.alibaba.fastjson2.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.study.talk.common.util.GsonUtil;
import com.study.talk.module.entity.vo.MomentVo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "Moment对象", description = "")
public class Moment {

    @ApiModelProperty("动态id")
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    @ApiModelProperty("发布者id")
    private Integer userId;

    @ApiModelProperty("发布者图片")
    private String avatar;

    @ApiModelProperty("发布者名称")
    private String userName;

    @ApiModelProperty("动态图片")
    private String photos;

    @ApiModelProperty("动态内容")
    private String content;

    @ApiModelProperty("点赞数")
    private Integer likeCount;

    @ApiModelProperty("创建时间")
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    @JSONField(format="yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createTime;

    public Moment(MomentVo momentVo) {
        this.userId = momentVo.getUserId();
        this.avatar = momentVo.getAvatar();
        this.userName = momentVo.getUserName();
        this.photos = GsonUtil.instance.toJson(momentVo.getPhotos());
        this.content = momentVo.getContent();
        this.likeCount = 0;
    }
}
